
Ext.onReady(function(){ 

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'under';

var record_start = 0; 

var sm = new Ext.grid.CheckboxSelectionModel();
var cm=new Ext.grid.ColumnModel([ 
sm,
new Ext.grid.RowNumberer({header: "编号",
width:40, 
renderer:function(value,metadata,record,rowIndex){ 
return record_start + 1 + rowIndex; 
} 
}),
{header:'信用评级',dataIndex:'confirmPdlevel',width:100,sortable:true}, 
{header:'评级流水号',dataIndex:'serialNo',width:120, hidden:true},
{header:'信用评级生成日期',dataIndex:'confirmDate',width:120,sortable:true},
{header:'PD值',dataIndex:'confirmPdvalue',width:100,sortable:true},
{header:'评级到期日',dataIndex:'endDate',width:100,sortable:true},
{header:'财报会计月份',dataIndex:'reportDate',width:100,sortable:true},
{header:'打分卡模型',dataIndex:'modelId',width:100,sortable:true},
{header:'初评人',dataIndex:'firstUserId',width:100,sortable:true},
{header:'初评机构',dataIndex:'firstOrgId',width:100,sortable:true},
{header:'评级状态',dataIndex:'phaseStat',width:120,sortable:true},
]); 
var ds=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'rating/listHistoryPD.do?isFromCustomer=1',
method:'POST'
}), 
reader:new Ext.data.JsonReader({ 
totalProperty:'total',  
root:'resultData'},[
{name:'serialNo'}, 
{name:'confirmDate'}, 
{name:'confirmPdlevel'}, 
{name:'endDate'}, 
{name:'modelId'},  
{name:'reportDate'},  
{name:'firstUserId'},  
{name:'firstOrgId'},  
{name:'confirmPdvalue'},
{name:'phaseStat'}
]) 
}); 



var grid=new Ext.grid.GridPanel({ 
id:'myCustomers',
renderTo:"rating_list", 
stripeRows:true,//斑马线效果
title:"历史评级信息", 
height:500, 
cm:cm,
store: ds, 
loadMask: { msg: "加载中..." }, 
viewConfig: {   
                            forceFit:true   
            },   
            bbar: new Ext.PagingToolbar({   
                pageSize: 20,   
                store: ds,   
                displayInfo: true,   
                displayMsg: '第{0} 到 {1} 条数据 共{2}条',   
                emptyMsg: "没有数据" ,
                doLoad : function(start){ 
   record_start = start; 
var o = {}, pn = this.getParams(); 
          o[pn.start] = start; 
          o[pn.limit] = this.pageSize; 
this.store.load({params:o}); 
     }  
            }),
 tbar: [
 {text:'评级详情',handler: PDDetail},
 ]              
});
ds.load({params:{start:0,limit:20}}); 


var tree = new Ext.tree.TreePanel
        ({ 
            animate:true,
            titleCollapse:true,
            root:root,
            singleExpand:false,
            iconCls:"icon-tree",
            autoLoad:false,
            allowDomMove:true,
            frame:true,
            collapsible:false,
            collapsed:false,
            collapseFirst:true,
            border:false,
            listeners:{ 
            	render:function(tree){ 
            		tree.el.on('click',function(e){ 
					e.stopPropagation(); }) ;
				} 
			} 
});

var loader=new Ext.tree.TreeLoader({dataUrl:'showExposureType.do'});

var root=new Ext.tree.AsyncTreeNode
        ({
         id:"0", 
         leaf:false,
         loader: loader,
         text:"风险暴露类型",
         expandable:true,
         expanded:true 
     });         

tree.setRootNode(root);

var comboTree =  Ext.getCmp('exposureTypeCombo');      

comboTree.on('expand',function(){tree.render('treePanel');});

var tree_click = function(node,e)
        {
            if(node.attributes.leaf)
            {
                if(node.isLeaf())
                {
                    e.stopEvent();   //非叶子节点则不触发
                    comboTree.setValue(node.id);  //设置option值
                    comboTree.setRawValue(node.text);
                    //comboTree.hiddenField.value = node.id;  
                	comboTree.collapse();   //隐藏option列表
                	//alert(comboTree.value);
                	//alert(comboTree.getValue());
                	//alert(comboTree.getRawValue());
                	//alert(comboTree.value);
                }
               
            }
        };
tree.on("click",tree_click);  

function startPD(){
	//var addForm = Ext.getCmp('addForm');
	//addForm.getForm().getEl().dom.reset(); 
	Ext.getCmp("addWin").buttons[0].handler = addFunction; 
	Ext.getCmp("addWin").show();

	//alert("链接跳转");
	//window.location.href="view/rating/CustomerRating_RatingProcess.jsp";
}

function addFunction() {

	if(addForm.form.isValid()){
			//alert("start Pd");
	
			var addPDForm=addForm.getForm().getEl().dom;
			addPDForm.action = 'rating/addPD.do';
			addPDForm.method = 'POST';
			addPDForm.submit();

//			 addForm.form.doAction('submit', { 
//
//                    url : 'rating/addPD.do', 
// 
//                    method : 'post', 
// 
//                       
//                       success : function() { 
//							
//                       
//                       
// 
//                       }, 
//                        failure : function(form, action) { 
//
//                          
// 
//                        } 
//                    }); 
	  
    }
    
}


function PDDetail(){
	if (grid.getSelectionModel().getSelections()[0] == undefined) { 
		Ext.Msg.alert("提示", "请选中要操作的项！"); 
	}
	else{
		var selectedSerialNo = grid.getSelectionModel().getSelections()[0].data.serialNo;
		//alert(selectedSerialNo);
		//window.location.href="rating/showHistoryPDList.do?custId="+selectedCustId;
		window.location.href="rating/showPDDetail.do?serialNo="+selectedSerialNo;
	}
}


function rowdblclickFn(grid, rowIndex, e){//双击事件  
             var row = grid.getStore().getAt(rowIndex); 
             var selectedCustId = row.get("serialNo");
             Ext.Ajax.request({
  url:'checkRequest.do',
  method:'GET',
  success:function(){
  window.location.href="rating/showPDDetail.do?serialNo="+selectedCustId;
  },failure:function(){
    Ext.MessageBox.alert("请求异常！");
  }
});  
        }   
grid.addListener('rowdblclick',rowdblclickFn);
}); 